<?php
global $VALUTA, $PLATEZH_TYPE, $MONTHS2;
$this->load->helper('form');

?>
<script language="javascript" src='<?=config_item('js_path')?>js/platezh_edit.js?<?=time()?>'></script>
<script language="javascript">
$(document).ready(function(){
	scheta = <?=json_encode($scheta)?>;
	VALUTA = <?=json_encode($VALUTA)?>;
	changeType();
	changeSchet();
});
</script>

<h1><?=lang('Редактирование платежа')?></h1>
<?php
if(!$platezh['can_delete'])
{
?>
<div class='error'>
	<?=lang('После этого платежа была совершена фиксация суммы. Поэтому отредактировать некоторые данные нельзя.<br>
	Удалить фиксацию суммы может только Ваш руководитель.')?>
</div><br><br>
<?php } ?>

<form method=post action='platezh/save' enctype='multipart/form-data' onsubmit="return checkForm(this)" id='f'>
	<input type='hidden' name='id' value='<?=@$platezh['id']?>'>
	<table class='edit' cellspacing=0 style="width:auto;">
		<tr>
			<td><b><?=lang('Тип')?></b></td>
			<td>
				<?php if($platezh['can_delete']) { ?>
					<select name='type' onchange="changeType();">
						<?php foreach($PLATEZH_TYPE as $k => $v) { ?>
							<option value='<?=$k?>' <?php if(@$platezh['type'] == $k) echo "selected"; ?>><?=$v?></option>
						<?php } ?>
					</select>
				<?php } else { ?>
					<input type='text' value='<?=$PLATEZH_TYPE[$platezh['type']]?>' readonly class='noborder'>
				<? } ?>
			</td>
		</tr>
		<tr>
			<td><b><?=lang('Счёт десятки')?></b></td>
			<td>
				<?php if(@$platezh['id'] && !isset($scheta[$platezh['schet_id']])) { ?>
					<?=lang('Используется счёт не моей десятки')?>
				<?php } else { ?>
					<?php if($platezh['can_delete']) { ?>
						<select name='schet_id' onchange="changeSchet()">
							<?php foreach($scheta as $s) { ?>
								<option value='<?=$s['id']?>' <?php if($s['id'] == @$platezh['schet_id']) echo "selected"; ?>><?=$s['name']?> <?=$VALUTA[$s['valuta']]?></option>
							<?php } ?>
						</select>
					<?php } else { 
						$s = $scheta[$platezh['schet_id']];
						?>
						<input type='text' value='<?=$s['name']." ".$VALUTA[$s['valuta']]?>' readonly class='noborder'>
					<? } ?>
				<?php } ?>
			</td>
		</tr>
		<tr>
			<td><?=lang('Валюта')?></td>
			<td id='valuta_text'>
				<input type='text' name='valuta' value='<?=@$VALUTA[$platezh['valuta']]?>' readonly class='noborder'>
			</td>
		</tr>
		<tr>
			<td><b><?=lang('Сумма')?></b></td>
			<td id='summ'>
				<input type='text' name='summ' value='<?=number_format(@$platezh['summ'], 2, $setting['znak_drob'], '')?>' <?php if(!$platezh['can_delete']) { ?>readonly class='noborder'<?php } ?>>
			</td>
		</tr>
		<tr id='row_komiss'>
			<td><?=lang('Комиссия')?></td>
			<td>
				<input type='text' name='komiss' value='<?=number_format(@$platezh['komiss'], 2, $setting['znak_drob'], '')?>' <?php if(!$platezh['can_delete']) { ?>readonly class='noborder'<?php } ?>>
			</td>
		</tr>
		<tr>
			<td><b><?=lang('Дата перевода')?></b></td>
			<td>
			<?php if($platezh['can_delete']) {
				$date_from = explode("-", @$platezh['from_date']);
				?>
				<select name='day_from'>
					<?php for($i = 1; $i<=31; $i++) {?>
						<option value='<?=$i?>' <?php if($i == @$date_from[2]) echo "selected"; ?>><?=$i?></option>
					<?php } ?>
				</select> . <select name='month_from'>
					<?php foreach($MONTHS2 as $k => $v) {?>
						<option value='<?=$k?>' <?php if($k == @$date_from[1]) echo "selected"; ?>><?=$v?></option>
					<?php } ?>
				</select> . <select name='year_from'>
					<?php for($i = 2011; $i<=(date("Y") + 1); $i++) {?>
						<option value='<?=$i?>' <?php if($i == @$date_from[0]) echo "selected"; ?>><?=$i?></option>
					<?php } ?>
				</select>
			<?php } else { ?>
				<input type='text' value='<?=getPrintDate($platezh['from_date'])?>' readonly class='noborder'>
			<?php } ?>
			</td>
		</tr>
		<tr id='row_date_postup'>
			<td><b><?=lang('Дата поступления')?></b></td>
			<td>
			<?php if($platezh['can_delete']) {
				$date_to = explode("-", @$platezh['to_date']);
				?>
				<select name='day_to'>
					<?php for($i = 1; $i<=31; $i++) {?>
						<option value='<?=$i?>' <?php if($i == @$date_to[2]) echo "selected"; ?>><?=$i?></option>
					<?php } ?>
				</select> . <select name='month_to'>
					<?php foreach($MONTHS2 as $k => $v) {?>
						<option value='<?=$k?>' <?php if($k == @$date_to[1]) echo "selected"; ?>><?=$v?></option>
					<?php } ?>
				</select> . <select name='year_to'>
					<?php for($i = 2011; $i<=(date("Y") + 1); $i++) {?>
						<option value='<?=$i?>' <?php if($i == @$date_to[0]) echo "selected"; ?>><?=$i?></option>
					<?php } ?>
				</select>
			<?php } else { ?>
				<input type='text' value='<?=getPrintDate($platezh['to_date'])?>' readonly class='noborder'>
			<?php } ?>
			</td>
		</tr>
		<?php if($platezh['can_delete']) { ?>
			<tr id='row_from_user_id'>
				<td><b><?=lang('От кого')?></b></td>
				<td><?=form_dropdown2('from_user_id', $children_user, @$platezh['from_user_id'], 'id', 'fio')?></td>
			</tr>
			<tr id='row_to_user_id'>
				<td><b><?=lang('Кому')?></b></td>
				<td><?=form_dropdown2('to_user_id', $children_user, @$platezh['to_user_id'], 'id', 'fio')?></td>
			</tr>
		<?php } ?>
		<tr id='row_from_people'>
			<td><b><?=lang('От кого')?></b></td>
			<td id=''>
				<?php if($platezh['can_delete']) { ?>
					<input type='text' name='from_people' value='<?=@$platezh['people']?>'>
				<?php } else { ?>
					<input type='text' value='<?=@$platezh['user_from']?>' readonly class='noborder'>
				<?php } ?>
			</td>
		</tr>
		<tr id='row_to_people'>
			<td><b><?=lang('Кому')?></b></td>
			<td id=''>
				<?php if($platezh['can_delete']) { ?>
					<input type='text' name='to_people' value='<?=@$platezh['people']?>'>
				<?php } else { ?>
					<input type='text' value='<?=@$platezh['user_to']?>' readonly class='noborder'>
				<?php } ?>
			</td>
		</tr>
		<tr>
			<td><?=lang('Ваш комментарий')?></td>
			<td><textarea name='comment' style="width:500px; height:100px;"><?=nl2br(htmlspecialchars(@$platezh['comment']))?></textarea></td>
		</tr>
		<?php for($i = 1; $i <= 5; $i++) { 
			$comment = @$platezh['file'.$i."_comment"] ? $platezh['file'.$i."_comment"] : lang('Комментарий');
			?>
			<tr>
				<td><?=lang('Файл')?> <?=$i?></td>
				<td>
					<?php if(@$platezh['file'.$i]) { ?>
						<a href='<?=UPLOAD_PATH.$platezh['file'.$i]?>' target=_blank><?=lang('Скачать')?></a><br>
					<?php } ?>
					<input type='file' name='file<?=$i?>'>
					<input type='text' name='file<?=$i?>_comment' value='<?=$comment?>' onfocus="if(this.value == '<?=lang('Комментарий')?>') this.value='';" onblur="if(this.value == '') this.value='<?=lang('Комментарий')?>';" style="width: 300px; color:#999999;">
				</td>
			</tr>
		<?php } ?>
	</table>
	<br>
	<input type='submit' name='save' value='<?=lang('Сохранить')?>'>

</form>


